package com.gourd.common.controller;

import com.gourd.common.constant.CommonConstant;
import com.gourd.common.kafka.service.KafkaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author gourd
 */
@RestController
@RequestMapping(value="/kafka",produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = "kafka", description = "kafka控制器")
public class KafkaMessageController {

    @Autowired
    private KafkaService kafkaService;
    
    @PostMapping(value="/message-send")
    @ApiOperation(value="kafka发送消息")
    public String send(@RequestParam String message){
        try {
            kafkaService.send(CommonConstant.TOPIC_ONE,message);
        } catch (Exception e) {
            return "send failed.";
        }
        return message;
    }

    @PostMapping(value="/message-send2")
    @ApiOperation(value="kafka发送消息2")
    public String sendTwo(@RequestParam String message){
        try {
            kafkaService.send(CommonConstant.TOPIC_TWO,message);
        } catch (Exception e) {
            return "send failed.";
        }
        return message;
    }
}